package com.ykh.controller;


import com.ykh.pojo.dto.PageParams;
import com.ykh.pojo.po.User;
import com.ykh.pojo.vo.ErrorCode;
import com.ykh.pojo.vo.Result;
import com.ykh.service.CollectUserVideoService;
import com.ykh.util.UserThreadLocal;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ykh
 * @since 2023年10月26日
 */
@RestController
@RequestMapping("/collectUserVideo")
public class CollectUserVideoController {
    @Autowired
    CollectUserVideoService collectUserVideoService;

    /**
     * 用户收藏视频接口
     */
    @ApiOperation("用户收藏视频接口")
    @PostMapping("/collect")
    public Result collect(@RequestParam Integer videoId) {
        User user = UserThreadLocal.get();
        if (user == null) {
            return Result.fail(ErrorCode.NO_LOGIN.getCode(), ErrorCode.NO_LOGIN.getMsg());
        }
        return Result.success(collectUserVideoService.collect(videoId, user.getAccount()));
    }


    /**
     * 用户获取收藏的视频接口
     */
    @ApiOperation("用户获取收藏的视频接口")
    @PostMapping("/list")
    public Result collectList(PageParams pageParams) {
        User user = UserThreadLocal.get();
        if (user == null) {
            return Result.fail(ErrorCode.NO_LOGIN.getCode(), ErrorCode.NO_LOGIN.getMsg());
        }
        return Result.success("查询成功", collectUserVideoService.collectList(pageParams, user.getAccount()));
    }

}


